package com.jcode.netty.client;

import com.jcode.netty.cmd.SysRequestCode;
import com.jcode.netty.protocol.Packet;
import com.jcode.netty.protocol.PacketUtil;
import io.netty.channel.Channel;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @Author dreajay
 * @DateTime 2016年12月13日 下午6:26:25
 */
public class NettyClientMain {

    private static final Logger log = LoggerFactory.getLogger(NettyClientMain.class);

    public static void main(String[] args) throws Exception {
        PropertiesConfiguration prop = new PropertiesConfiguration("config.properties");
        final String serverIp = "127.0.0.1:8888";

        ClientConfig config = new ClientConfig();
        config.setConnectTimeoutMillis(6000000);
        config.setClientWorkerThreads(2);
        config.setClientChannelMaxIdleTimeSeconds(5);// 5秒空闲
        config.setServerAddress(serverIp);
        NettyClient client = new NettyClient(config);
        client.start();
        Packet packet = PacketUtil.createRequestPacket(SysRequestCode.PING);
        client.sendRequestSync(packet);
    }
}
